package com.zx.练习题.demo;

public class T1 {

    public static void main(String[] args) {
        Node root = new Node(0);
        Node n1 = new Node(1);
        root.next = n1;
        Node n2 = new Node(2);
        n1.next = n2;
        Node n3 = new Node(3);
        n2.next = n3;
        Node n4 = new Node(4);
        n3.next = n4;
        n4.next = n2;

        Node slow = root;
        Node fast = root.next;
        boolean isRound = false;
        while (fast != null && slow != null) {
            System.out.println(fast.data + " = " + slow.data);
            if (fast.data == slow.data) {
                isRound = true;
                break;
            } else {
                fast = fast.next != null ? fast.next.next : null;
                slow = slow.next;
            }
        }
        System.out.println(isRound);

    }

    public static class Node {

        int data;
        Node next;

        public Node(int data) {
            this.data = data;
        }
    }

}
